//
//  WishTableViewCell.m
//  ShrimpCrowdordering
//
//  Created by 郑洲 on 2018/7/26.
//  Copyright © 2018年 郑洲. All rights reserved.
//

#import "WishTableViewCell.h"

@interface WishTableViewCell ()

@property (nonatomic, strong) UIImageView *headView;
@property (nonatomic, strong) UILabel *nameLabel;

@property (nonatomic, strong) UIImageView *goodsView;
@property (nonatomic, strong) UILabel *goodsName;
@property (nonatomic, strong) UILabel *goodsNum;
@property (nonatomic, strong) UILabel *goodsPrice;

@end

@implementation WishTableViewCell

- (void)setWishModel:(WishModel *)wishModel {
    _wishModel = wishModel;
    self.nameLabel.text = wishModel.proUserName;
    [self.headView sd_setImageWithURL:[NSURL URLWithString:wishModel.proUserPic] placeholderImage:nil options:SDWebImageRetryFailed];
    self.goodsName.text = wishModel.proName;
    [self.goodsView sd_setImageWithURL:[NSURL URLWithString:wishModel.proPic] placeholderImage:nil options:SDWebImageRetryFailed];
    NSString *moneyStr = [NSString stringWithFormat:@"%.2f元",[wishModel.proPrice floatValue]];
    NSMutableAttributedString *attributedStr = [[NSMutableAttributedString alloc] initWithString:moneyStr];
    [attributedStr addAttribute:NSForegroundColorAttributeName value:REXADECIMALCOLOR(@"#f21934") range:NSMakeRange(0, [moneyStr length] - 1)];
    self.goodsPrice.attributedText = attributedStr;
}

+ (WishTableViewCell *)cellWithTableView:(UITableView *)tableView andIndexPath:(NSIndexPath *)indexPath{
    static NSString *cellID = @"WishTableViewCell";
    WishTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellID];
    if (cell == nil) {
        cell = [[WishTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellID];
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
        cell.backgroundColor = TABLEVIEW_BACKGROUNDCOLOR;
        [cell createSubView];
    }
    
    return cell;
}

- (void)createSubView {
    UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, ScreenX375(211))];
    view.backgroundColor = [UIColor whiteColor];
    [self addSubview:view];
    
    self.headView = [[UIImageView alloc] initWithFrame:CGRectMake(ScreenX375(16), ScreenX375(11), ScreenX375(26), ScreenX375(26))];
    self.headView.clipsToBounds = YES;
    self.headView.layer.cornerRadius = ScreenX375(13);
    self.headView.image = ImageWithName(@"头像1");
    [self addSubview:self.headView];
    
    self.nameLabel = [[UILabel alloc] initWithFrame:CGRectMake(ScreenX375(52), ScreenX375(16), ScreenX375(100), ScreenX375(16))];
    self.nameLabel.textColor = FONTCOLOR_BLACK;
    self.nameLabel.font = Kfont(14);
    self.nameLabel.text = @"南有佳人";
    [self addSubview:self.nameLabel];
    
    UIView *tLine = [[UIView alloc] initWithFrame:CGRectMake(ScreenX375(16), ScreenX375(48.5), SCREEN_WIDTH - 2 * ScreenX375(16), ScreenX375(0.5))];
    tLine.backgroundColor = LineColor;
    [self addSubview:tLine];
    
    self.goodsView = [[UIImageView alloc] initWithFrame:CGRectMake(ScreenX375(16), ScreenX375(62), ScreenX375(80), ScreenX375(80))];
    self.goodsView.image = ImageWithName(@"2");
    self.goodsView.contentMode = UIViewContentModeScaleAspectFill;
    self.goodsView.clipsToBounds = YES;
    [self addSubview:self.goodsView];
    
    self.goodsName = [[UILabel alloc] initWithFrame:CGRectMake(ScreenX375(106), ScreenX375(62), ScreenX375(200), ScreenX375(15))];
    self.goodsName.textColor = FONTCOLOR_BLACK;
    self.goodsName.font = Kfont(15);
    self.goodsName.text = @"印花的设计纯棉纸巾";
    [self addSubview:self.goodsName];
    
    self.goodsNum = [[UILabel alloc] initWithFrame:CGRectMake(ScreenX375(106), ScreenX375(84), ScreenX375(150), ScreenX375(15))];
    self.goodsNum.textColor = FONTCOLOR_BLACK;
    self.goodsNum.font = Kfont(15);
    self.goodsNum.text = @"x 1";
    [self addSubview:self.goodsNum];
    
    self.goodsPrice = [[UILabel alloc] initWithFrame:CGRectMake(ScreenX375(106), ScreenX375(124), ScreenX375(150), ScreenX375(18))];
    self.goodsPrice.textColor = FONTCOLOR_BLACK;
    self.goodsPrice.font = Kfont(18);
    self.goodsPrice.text = @"168.80元";
    [self addSubview:self.goodsPrice];
    
    UIView *Line = [[UIView alloc] initWithFrame:CGRectMake(ScreenX375(16), ScreenX375(154), SCREEN_WIDTH - 2 * ScreenX375(16), ScreenX375(0.5))];
    Line.backgroundColor = LineColor;
    [self addSubview:Line];
    
    UIButton *chatBtn = [[UIButton alloc] initWithFrame:CGRectMake(ScreenX375(179), ScreenX375(167), ScreenX375(85), ScreenX375(33))];
    [chatBtn setTitle:@"联系客服" forState:UIControlStateNormal];
    [chatBtn setTitleColor:FONTCOLOR_BLACK forState:UIControlStateNormal];
    chatBtn.layer.borderColor = REXADECIMALCOLOR(@"#f0f0f0").CGColor;
    chatBtn.layer.borderWidth = 1;
    chatBtn.clipsToBounds = YES;
    chatBtn.titleLabel.font = Kfont(14);
    chatBtn.layer.cornerRadius = ScreenX375(16.5);
    [chatBtn addTarget:self action:@selector(chat) forControlEvents:UIControlEventTouchUpInside];
    [self addSubview:chatBtn];
    
    UIButton *payBtn = [[UIButton alloc] initWithFrame:CGRectMake(ScreenX375(275), ScreenX375(167), ScreenX375(85), ScreenX375(33))];
    [payBtn setTitle:@"立即付款" forState:UIControlStateNormal];
    [payBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    [payBtn setBackgroundImage:[UIImage imageNamed:@"按钮背景"] forState:UIControlStateNormal];
    payBtn.clipsToBounds = YES;
    payBtn.titleLabel.font = Kfont(14);
    payBtn.layer.cornerRadius = ScreenX375(16.5);
    [payBtn addTarget:self action:@selector(buy) forControlEvents:UIControlEventTouchUpInside];
    [self addSubview:payBtn];
}

- (void)chat {
    if (_chatClick) {
        _chatClick();
    }
}

- (void)buy {
    if (_buyClick) {
        _buyClick();
    }
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end

@implementation WishModel


@end
